package com.project.controller;

import com.project.model.*;
import com.project.service.GetStuidService;
import com.project.service.ShopCarService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class ShopCarController {
	private ShopCarService shopCarService;
	private GetStuidService getStuidService;
	
	@Autowired
	public void setGetStuidService(GetStuidService getStuidService) {
		this.getStuidService = getStuidService;
	}
	@Autowired
	public void setShopCarService(ShopCarService shopCarService){
		this.shopCarService=shopCarService;
	}
	public ShopCarService getShopCarService(){
		return shopCarService;
	}
	public GetStuidService getGetStuidService(){
		return getStuidService;
	}
	
	
	@RequestMapping("/selectshoporder")
	public Map<String,String> SelectShoporder(HttpServletRequest request){
	
//		HttpSession session=request.getSession();
//		User user=(User)session.getAttribute("user");
		User user=new User();
    	user.setUid(1);
		Stu stu=getStuidService.selectStuid(user);
		String stuid=null;
		stuid=stu.getStuid();
		
		Map<String, String> map = new HashMap<String, String>();
		JSONObject json=new JSONObject();
		List<Shopcart> list1=this.getShopCarService().selectShopcart(stuid);
		for (int j=0;j<list1.size()&&list1!=null;j++) {
			Totalorder totalorder=this.getShopCarService().toselectShoporder(list1.get(j).getTotalorder().getTid());
			String a=totalorder.getTid();
			String b=totalorder.getTtype();
			String c=totalorder.getCompany().getCompanyname();
			String d=totalorder.getMyadd().getMyaddress();
			String e=totalorder.getMyadd().getMyaddhousenum();
			String f=totalorder.getMyadd().getMyaddroomnum();
			map.put("订单编号", a);
			map.put("订单类别", b);
			map.put("快递公司", c);
			map.put("地址", d + e + f);
			json.put(j++,map);
		}
		return json;
	}
	
}
